#ifndef PATTERN_H_INCLUDED
#define PATTERN_H_INCLUDED

/*
    XHoldingPattern
    Copyright (C) 2009 Mike Gehl

    X-Plane Plugin SDK
    Copyright (C) Sandy Barbour and Ben Supnik

    This file is part of XHoldingPattern.

    XHoldingPattern is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    XHoldingPattern is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with XHoldingPattern.  If not, see <http://www.gnu.org/licenses/>.
    ---------------------------------------------------------------------------
    pattern.h
    Copyright (C) Mike Gehl 2009 <mjgehl@gmail.com>
*/

#include <math.h>

static const float METERS_TO_MILES = 0.000621371192;

typedef enum
{
    PATTERN_LEFT = -1,
    PATTERN_RIGHT = 1
} PATTERN_DIR;

typedef enum
{
    INTERCEPT = 0,
    INBOUND_LEG = 1,
    OUTBOUND_TURN = 2,
    OUTBOUND_LEG = 3,
    INBOUND_TURN = 4
} PATTERN_LEG;

// Copyright (C) 2005-2006 Alexander Wemmer
inline static double trimHeading(double hdg)
{
    while (hdg < 0.0) hdg += 360.0;
    while (hdg >= 360.0) hdg -= 360.0;
    return hdg;
}

typedef struct tagPATTERN_DATA
{
    double  radius;     // Radius of earth in meters
    double  navaid_lat; // Lattitude of Navaid
    double  navaid_lon; // Longitude of Navaid
    double  plane_lat;  // Lattitude of aricraft position
    double  plane_lon;  // Longitude of aricraft position
    double  distance;   // Distance in meters to navaid
    float   wind_speed; // Wind Speed at current altitude
    float   wind_dir;   // Wind Direction at current altitude
    float   heading;    // Heading to fly
    float   course;     // Inbound leg pattern course
    PATTERN_DIR direction;  // Traffic pattern direction
    PATTERN_LEG leg;        // Current leg of pattern
} PATTERN_DATA;


double deg2rad(double);
double rad2deg(double);
double meters2miles(double);

void update_position(double, double, PATTERN_DATA*);

void pattern_intercept(PATTERN_DATA*);



#endif // PATTERN_H_INCLUDED
